#ifndef QUE_H
#define QUE_H
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_timer.h"

#define BUTTON_TOTAL_NUM 10

#define BUTTON_PIN_0    0
#define BUTTON_PIN_1    1
#define BUTTON_PIN_2    2
#define BUTTON_PIN_3    3
#define BUTTON_PIN_4    4
#define BUTTON_PIN_5    5
#define BUTTON_PIN_6    6
#define BUTTON_PIN_7    7
#define BUTTON_PIN_8    8
#define BUTTON_PIN_9    9

#define BUTTON_PIN GPIO_NUM_17
#define DEBOUNCE_TIME 10 // 消抖时间（毫秒）
#define SHORT_PRESS_TIME 300 // 短按时间阈值（毫秒）
#define LONG_PRESS_TIME 1000 // 长按时间阈值（毫秒）

#define BUTTOM_0 BIT0
#define BUTTOM_1 BIT1
#define BUTTOM_2 BIT2
#define BUTTOM_3 BIT3
#define BUTTOM_4 BIT4
#define BUTTOM_5 BIT5
#define BUTTOM_6 BIT6
#define BUTTOM_7 BIT7
#define BUTTOM_8 BIT8
#define BUTTOM_9 BIT9
#define BUTTOM_10 BIT10
#define BUTTOM_11 BIT11

// 按键事件结构体
typedef struct {
    uint32_t gpio_num; // 按键GPIO引脚编号
    int64_t time;     // 按键时间戳
    bool pressed;      // 按键状态（按下或释放）
} button_event_t;

typedef struct{
    uint8_t A_PIN : 1;
    uint8_t B_PIN : 1;
    uint8_t C_PIN : 1;
    uint8_t D_PIN : 1;
    uint8_t E_PIN : 1;
    uint8_t F_PIN : 1;
    uint64_t txt_index;
} keyboard_event_t;

typedef enum{
    NO_PRESS = 0 ,
    PRESS_SINGLE,
    PRESS_DOUBLE,
    PRESS_LONG
}button_state_t;

typedef enum{
    DEFAULT  = 0,
    SHOW_MODE  ,
    WRITE_MODE
}mode_state_t;

typedef enum{
    DEFAULT_p = 0 ,
    TURN_PAGE_p ,
    AHEAD_PAGE_p,
    NEXT_WOLD_p,
    AHEAD_WOLD_p
}pin_turn_state_t;
extern pin_turn_state_t pin_turn_state;
extern mode_state_t mode_state;
extern button_state_t button_state[BUTTON_TOTAL_NUM];
extern EventGroupHandle_t button_event_group;

void que_int_user(void);

#endif